/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectodbtienda;

import javax.swing.JOptionPane;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Shaka
 */
public class TablesAdm extends javax.swing.JFrame {

    public int indx;
    public int ida;
    private Connection conn;
    private Statement stmt;
    private ResultSet rst;
     private Connection connr;
    private Statement stmtr;
    private ResultSet rstr;
    private DefaultTableModel modelo;

    /** Creates new form Tables */
    public TablesAdm() {
        try {
            initComponents();
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version 1433
            conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1051;databaseName=tienda;user=sa;password=ecliptica;");//iti
            //conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1055;databaseName=test;user=sa;password=fernanda;");//fer
            stmt = conn.createStatement();
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version 1433
            connr = DriverManager.getConnection("jdbc:sqlserver://tecnoserver;databaseName=002;user=sa;password=Abc1234.;");//iti
            //conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1055;databaseName=test;user=sa;password=fernanda;");//fer
            stmtr = connr.createStatement();
        } catch (SQLException excepcionSql) { //excepcionSql = puede ponerle otro nombre
            JOptionPane.showMessageDialog(null, excepcionSql.getMessage(),
                    "Error en base de datos", JOptionPane.ERROR_MESSAGE);
        } //errores con la carga del controlador de la base de datos(Driver)
        catch (ClassNotFoundException claseNoEncontrada) {
            JOptionPane.showMessageDialog(null, claseNoEncontrada.getMessage(),
                    "No se encontró el controlador", JOptionPane.ERROR_MESSAGE);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton4 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        jButton4.setText("Agregar Usuario");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Seleccione La tabla a Mostrar"));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Tabla:");
        jPanel1.add(jLabel1);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Usuarios", "Ciudades", "Clientes", "Compras", "Detalle de Compras", "Detalle de Venta", "Estados", "Productos", "Proveedores", "Ventas", "Clientes Remotos" }));
        jPanel1.add(jComboBox1);

        jButton3.setText("Mostrar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3);

        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton1.setText("Agregar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1);

        jButton2.setText("Eliminar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);

        jButton5.setText("Restaurar Pass");
        jButton5.setEnabled(false);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton5);

        jButton6.setText("Activar");
        jButton6.setEnabled(false);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton6);

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_END);

        jMenu1.setText("Usuario");

        jMenuItem1.setText("Modificar Password");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        indx = jComboBox1.getSelectedIndex();
        Object ob[];
        DefaultTableModel model;
        try {
            switch (indx) {

                case 0:
                    jButton5.setEnabled(true);
                    jButton6.setEnabled(false);
                    ob = new Object[4];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("ID");
                    model.addColumn("UserName");
                    model.addColumn("Password");
                    model.addColumn("Nivel");
                    modelo = model;

                    rst = stmt.executeQuery("select * from users");
                    while (rst.next()) {
                        ob[0] = rst.getInt("iduser");
                        ob[1] = rst.getString("username");
                        ob[2] = rst.getString("pass");
                        ob[3] = rst.getString("nivel");
                        modelo.addRow(ob);


                    }
                    //conn.close();//se cierra la conexion con la base de datos

                    break;
                case 1:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(false);
                    ob = new Object[3];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDCiudad");
                    model.addColumn("Nombre");
                    model.addColumn("IDEstado");
                    modelo = model;

                    rst = stmt.executeQuery("select * from Ciudades");
                    while (rst.next()) {
                        ob[0] = rst.getInt("IdCiudad");
                        ob[1] = rst.getString("nombreCiudad");
                        ob[2] = rst.getString("IdEstado");
                        modelo.addRow(ob);
                    }
                    break;
                case 2:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(true);
                    ob = new Object[7];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDCliente");
                    model.addColumn("Nombre");
                    model.addColumn("RFC");
                    model.addColumn("Teléfono");
                    model.addColumn("Dirección");
                    model.addColumn("IDCiudad");
                    model.addColumn("Activo");
                    modelo = model;

                    rst = stmt.executeQuery("select * from clientes");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idcliente");
                        ob[1] = rst.getString("nombre");
                        ob[2] = rst.getString("rfc");
                        ob[3] = rst.getString("telefono");
                        ob[4] = rst.getString("direccion");
                        ob[5] = rst.getString("idCiudad");
                        ob[6] = rst.getString("activo");
                        modelo.addRow(ob);
                    }
                    break;
                case 3:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(false);
                    ob = new Object[4];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDCompras");
                    model.addColumn("Importe");
                    model.addColumn("IDProveedor");
                    model.addColumn("Fecha de Compra");
                    modelo = model;

                    rst = stmt.executeQuery("select * from compras");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idcompra");
                        ob[1] = rst.getString("importe");
                        ob[2] = rst.getString("idproveedor");
                        ob[3] = rst.getString("fechacompra");
                        modelo.addRow(ob);
                    }
                    break;
                case 4:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(false);
                    ob = new Object[5];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDDetalle");
                    model.addColumn("IDCompra");
                    model.addColumn("IDProducto");
                    model.addColumn("Cantidad");
                    model.addColumn("Importe");
                    modelo = model;

                    rst = stmt.executeQuery("select * from detallecompras");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idDcompras");
                        ob[1] = rst.getString("idcompra");
                        ob[2] = rst.getString("idproducto");
                        ob[3] = rst.getString("cantidad");
                        ob[4] = rst.getString("importe");
                        modelo.addRow(ob);
                    }
                    break;
                case 5:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(false);
                    ob = new Object[5];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDDetalle");
                    model.addColumn("IDVenta");
                    model.addColumn("IDProducto");
                    model.addColumn("Cantidad");
                    model.addColumn("Importe");
                    modelo = model;

                    rst = stmt.executeQuery("select * from detalleVenta");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idDventa");
                        ob[1] = rst.getString("idventa");
                        ob[2] = rst.getString("idproducto");
                        ob[3] = rst.getString("cantidad");
                        ob[4] = rst.getString("importe");
                        modelo.addRow(ob);
                    }
                    break;
                case 6:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(false);
                    ob = new Object[2];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDEstado");
                    model.addColumn("Nombre Estado");
                    modelo = model;

                    rst = stmt.executeQuery("select * from Estados");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idEstado");
                        ob[1] = rst.getString("nombreEstado");
                        modelo.addRow(ob);
                    }
                    break;
                case 7:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(true);
                    ob = new Object[6];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDProducto");
                    model.addColumn("Nombre");
                    model.addColumn("Precio");
                    model.addColumn("Existencia");
                    model.addColumn("IDProveedor");
                    model.addColumn("Activo");
                    modelo = model;

                    rst = stmt.executeQuery("select * from productos");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idproducto");
                        ob[1] = rst.getString("nombre");
                        ob[2] = rst.getString("precio");
                        ob[3] = rst.getString("existencia");
                        ob[4] = rst.getString("idproveedor");
                        ob[5] = rst.getString("activo");
                        modelo.addRow(ob);
                    }
                    break;
                case 8:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(true);
                    ob = new Object[5];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDProveedor");
                    model.addColumn("RFC");
                    model.addColumn("Nombre");
                    model.addColumn("Dirección");
                    model.addColumn("Activo");
                    modelo = model;

                    rst = stmt.executeQuery("select * from proveedores");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idproveedor");
                        ob[1] = rst.getString("RFC");
                        ob[2] = rst.getString("Nombre");
                        ob[3] = rst.getString("direccion");
                        ob[4] = rst.getString("activo");
                        modelo.addRow(ob);
                    }
                    break;
                case 9:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(false);
                    ob = new Object[4];
                    model = new DefaultTableModel();
                    jTable1.setModel(model);
                    model.addColumn("IDVenta");
                    model.addColumn("IDCliente");
                    model.addColumn("Fecha de Venta");
                    model.addColumn("Total");
                    modelo = model;

                    rst = stmt.executeQuery("select * from ventas");
                    while (rst.next()) {
                        ob[0] = rst.getInt("idventa");
                        ob[1] = rst.getString("idcliente");
                        ob[2] = rst.getString("fechaVenta");
                        ob[3] = rst.getString("total");
                        modelo.addRow(ob);
                    }
                    break;
                case 10:
                    jButton5.setEnabled(false);
                    jButton6.setEnabled(true);
                     ob = new Object[7];
                model = new DefaultTableModel();
                jTable1.setModel(model);
                model.addColumn("IDCliente");
                model.addColumn("Nombre");
                model.addColumn("Dirección");
                model.addColumn("Teléfono");
                model.addColumn("IDCiudad");
                model.addColumn("RFC");
                model.addColumn("Activo");
                modelo = model;

                 rstr=stmtr.executeQuery("select * from clientes");
            while(rstr.next()){

                ob[0] =rstr.getInt("idcliente");
                ob[1] = rstr.getString("nombre");
                ob[2] = rstr.getString("direccion");
                ob[3] = rstr.getString("telefono");
                ob[4] = rstr.getString("idciudad");
                ob[5] = rstr.getString("rfc");
                ob[6] = rstr.getInt("activo");
                modelo.addRow(ob);}
                    break;
            }
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:        
        System.out.println(indx);
        AddDataAdmin ad = new AddDataAdmin(indx);
        ad.setVisible(true);

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        String Sindx = "";
        int h;
        try {
            switch (indx) {
                case 0:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from users where iduser=" + Sindx);
                    JOptionPane.showMessageDialog(null, "usuario eliminado");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 1:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from ciudades where idCiudad=" + Sindx);
                    JOptionPane.showMessageDialog(null, "ciudad eliminada");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 2:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("update clientes set activo ='n' where idcliente=" + Sindx);
                    JOptionPane.showMessageDialog(null, "cliente pasó a no activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 3:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from compras where idcompra=" + Sindx);
                    JOptionPane.showMessageDialog(null, "compra eliminada");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 4:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from detallecompras where idDcompras=" + Sindx);
                    JOptionPane.showMessageDialog(null, "detalle de compra eliminda");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 5:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from detalleventa where idDventa=" + Sindx);
                    JOptionPane.showMessageDialog(null, "detalle de venta eliminada");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 6:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from Estados where IdEstado=" + Sindx);
                    JOptionPane.showMessageDialog(null, "estado eliminado");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 7:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("update productos set activo ='n' where idproducto=" + Sindx);
                    JOptionPane.showMessageDialog(null, "producto pasó a no activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 8:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("update proveedores set activo ='n' where idproveedor=" + Sindx);
                    JOptionPane.showMessageDialog(null, "proveedor pasó a no activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 9:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("delete from ventas where idventa=" + Sindx);
                    JOptionPane.showMessageDialog(null, "venta eliminada");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 10:
                     h = jTable1.getSelectedRow();
                  Sindx +=  jTable1.getValueAt(h,0);
                  stmtr.executeUpdate("update clientes set activo = 0 where idcliente="+Sindx);
                  JOptionPane.showMessageDialog(null, "cliente pasó a no activo");
                  if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                  break;

            }

        } catch (SQLException ex) {
            Logger.getLogger(AddData.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        int h;
        String Uname = "";
        try {
            h = jTable1.getSelectedRow();
            Uname += jTable1.getValueAt(h, 1);
            stmt.executeUpdate("update users set pass ='" + Uname + "' where username='" + Uname + "'");
            JOptionPane.showMessageDialog(null, "Password restaurado");

            //conn.close();//se cierra la conexion con la base de datos
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        ModPass mp = new ModPass();
        mp.id = ida;
        mp.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        String Sindx = "";
        int h;
        try {
            switch (indx) {
                case 2:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("update clientes set activo ='s' where idcliente=" + Sindx);
                    JOptionPane.showMessageDialog(null, "cliente pasó a activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 7:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("update productos set activo ='s' where idproducto=" + Sindx);
                    JOptionPane.showMessageDialog(null, "producto pasó a activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 8:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmt.executeUpdate("update proveedores set activo ='s' where idproveedor=" + Sindx);
                    JOptionPane.showMessageDialog(null, "proveedor pasó a activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;
                case 10:
                    h = jTable1.getSelectedRow();
                    Sindx += jTable1.getValueAt(h, 0);
                    stmtr.executeUpdate("update clientes set activo =1 where idcliente=" + Sindx);
                    JOptionPane.showMessageDialog(null, "cliente pasó a activo");
                    if (jTable1 != null) {
                        while (jTable1.getColumnCount() > 0) {
                            TableColumn col = jTable1.getColumnModel().getColumn(0);
                            jTable1.removeColumn(col);
                        }
                    }
                    jButton3ActionPerformed(evt);
                    break;

            }

        } catch (SQLException ex) {
            Logger.getLogger(AddData.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TablesAdm().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1;
    public javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
